package com.fc.app.fcapp.customview;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.baidu.tvsafe.TVSafe;
import com.fc.app.fcapp.R;
import com.fc.library.fresco.Util;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import rx.Observable;
import rx.Subscriber;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.functions.Func1;


/**
 * Created by fc on 2018/2/26.
 */

public class CustomViewActivity extends Activity {
    private final String TAG = "baiduResult";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_custom_view);
        final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.custom_mainLayout);
        Button button = (Button) findViewById(R.id.dns_btn);
        Button button1 = (Button) findViewById(R.id.path_btn);
        button.postDelayed(new Runnable() {
            @Override
            public void run() {
            }
        },500);


        final FrameLayout frameLayout = new FrameLayout(getApplicationContext());
        linearLayout.addView(frameLayout);


        final PathLine pathLine = new PathLine(getApplicationContext());
        frameLayout.addView(pathLine);

        Log.i(TAG, "onCreate: "+(float)( (102.86f / 1024)));

        Log.i(TAG, "onCreate111: "+(float)( (1.f / 100)));


        button1.setOnClickListener(new View.OnClickListener() { //path 按钮
            @Override
            public void onClick(View v) {
                //测试数据
                List<Point> pointList = new ArrayList<>();
                Point p = new Point(100, 410);
                pointList.add(p);
                p = new Point(200, 310);
                pointList.add(p);
                p = new Point(300, 340);
                pointList.add(p);
                p = new Point(400, 300);
                pointList.add(p);
                p = new Point(500, 350);
                pointList.add(p);
                p = new Point(600, 320);
                pointList.add(p);

                PathLine bluePathLine = new PathLine(getApplicationContext());
                bluePathLine.setPainColor(Color.parseColor("#0171d6"));
                bluePathLine.setPointList(pointList);
                FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                frameLayout.addView(bluePathLine, params);

                PathShadowView bluePathShadowView = new PathShadowView(getApplicationContext());
                bluePathShadowView.setPainColor(Color.parseColor("#800171d6"), Color.parseColor("#000171d6"));
                bluePathShadowView.setPointList(pointList);
                params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                frameLayout.addView(bluePathShadowView, params);

            }
        });

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                DynamicDrawView dynamicDrawView = new DynamicDrawView(getApplicationContext());
                frameLayout.addView(dynamicDrawView);


                Log.i(TAG, "***********************点击事件调用相关API*******************   ");
                if (TVSafe.startNetScanner()) {
                    Log.i(TAG, "TVSafe.startNetScanner()    succeed");
                } else {
                    Log.i(TAG, "TVSafe.startNetScanner()    fail");
                }
                if (TVSafe.getIPsUrlByDomainUrl("www.baidu.com")) {
                    Log.i(TAG, "TVSafe.getIPsUrlByDomainUrl(\"www.baidu.com\")  succeed");
                } else {
                    Log.i(TAG, "TVSafe.getIPsUrlByDomainUrl(\"https://www.baidu.com/\")  fail");
                }

                if (TVSafe.queryUrlSafeLevel("https://www.baidu.com/")) {
                    Log.i(TAG, "TVSafe.queryUrlSafeLevel(\"https://www.baidu.com/\")    succeed");
                } else {
                    Log.i(TAG, "TVSafe.queryUrlSafeLevel(\"https://www.baidu.com/\")    fail");
                }

                if (TVSafe.fixDns()) {
                    Log.i(TAG, "TVSafe.fixDns()  succeed");
                } else {
                    Log.i(TAG, "TVSafe.fixDns()  fail");
                }


            }
        });


        MoveView moveView = (MoveView) findViewById(R.id.move_view);
        moveView.smoothScrollTo(-400, 0);
        Observable observable = Observable.create(new Observable.OnSubscribe<String>() {

            @Override
            public void call(Subscriber<? super String> subscriber) {
                subscriber.onNext("1111");
                subscriber.onNext("222");
                subscriber.onNext("333");
            }
        });

        Observable observable1 = Observable.just("111", "222", "333");

        String[] words = {"111", "222"};
        Observable observable2 = Observable.from(words);

        observable.subscribe();

        Action0 onComple = new Action0() {
            @Override
            public void call() {
                Log.i("xxx", "not exists");
            }
        };

        Observable.interval(3, TimeUnit.SECONDS).subscribe(new Action1<Long>() {
            @Override
            public void call(Long aLong) {
//                Log.i("xxx"," Observable.interval");
            }
        });


        final String fc = "FFFFFFFFFCCCCCCCCCCCCCC";
        Observable.just("____111").map(new Func1<String, String>() {

            @Override
            public String call(String s) {
                return fc + s;
            }
        }).subscribe(new Action1<String>() {
            @Override
            public void call(String s) {
                Log.i("xxx", s);
            }
        });

        final List<String> list = new ArrayList<>();
        list.add("----1111");
        list.add("----2222");
        list.add("----3333");
        list.add("----4444");
        Observable.from(list).flatMap(new Func1<String, Observable<?>>() {
            @Override
            public Observable<?> call(String s) {
                return Observable.just(fc + s);
            }
        }).cast(String.class).subscribe(new Action1<String>() {
            @Override
            public void call(String s) {
                Log.i("xxx", "flatMap " + s);
            }
        });



    }
}
